If and else condition not working properly in xna [closed]

Posted by user1090751 on Game Development See other posts from Game Development or by user1090751
Published on 2012-10-05T17:44:08Z Indexed on 2012/10/05 21:55 UTC
Read the original article Hit count: 116

Filed under:
|

I am developing chess like game and i wanted to show error message if user try to place any player inside the box which is not empty. For example in certain place if there is empty then the object(2d object) is placed else it should show error message. However in my program it is showing message everytime i.e when i place object on empty place then also it is showing error message. Please see the below code:

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        for (int i = 0; i < 25; i++)
        {
            MouseState mouseState;
            mouseDiBack = false;
            mouseState = Mouse.GetState();

            if (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(rect_arr[i]))
            {
                background_color_arr[i] = Color.Red;                   

            }
            else
            {
                background_color_arr[i] = Color.White;

            }

            if (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(rect_arr[i]) && (mouseState.LeftButton == ButtonState.Pressed))
            {                   

                if (boxes[i] != "goat" && boxes[i] != "tiger")
                {
                    place = i;
                    if (turn == "goat")
                    {
                        boxes[i] = "goat";
                        turn = "tiger";
                    }
                    else
                    {
                        boxes[i] = "tiger";
                        turn = "goat";
                    }
                }
                else {
                    errMsg = "This " + i + " block is not empty to place " + turn + ". Please select empty block!!";
                }

            }               
        }



        base.Update(gameTime);
    }

© Game Development or respective owner

Related posts about XNA

Related posts about logic